class Solution {
    public String removeDuplicates(String s) {
        StringBuffer str = new StringBuffer();
        char[] chs = s.toCharArray();
        for (char ch : chs) {
            if (str.length() > 0 && ch == str.charAt(str.length() - 1)) {
                str.deleteCharAt(str.length() - 1);
            } else {
                str.append(ch);
            }
        }
        return str.toString();
    }
}